package admin

import (
	"strconv"
	"strings"
	//"pfl/db"

	"github.com/astaxie/beego"
)

type IndexController struct {
	beego.Controller
}

func GetUserIdBySession(c *IndexController) (int, bool) {
	str := c.Ctx.Input.Session(SessionKey)
	if str == nil {
		return 0, false
	}
	strs := strings.Split(str.(string), ":")
	if strs == nil || len(strs) != 4 {
		return 0, false
	}
	id, err := strconv.Atoi(strs[1])
	if err != nil {
		return 0, false
	}
	return id, true
}

func (c *IndexController) Get() {
	/*id, ok := GetUserIdBySession(c)
	if !ok {
		c.Redirect("/", 302)
		return
	}
	Carousels := make([]models.Carousel, 0)
	db.Mysql.Find(&Carousels)
	for _, v := range Carousels {
		str1 := fmt.Sprintf("Carousels_img_%d", v.Id)
		str2 := fmt.Sprintf("Carousels_desc_%d", v.Id)
		c.Data[str1] = v.Pic
		c.Data[str2] = v.Url
	}
	c.Data["Id"] = id
	*/
	c.TplName = "admin/index.html"
}
